package com.itheima.web.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Date;

/**
 * @Author:Mr.yuan
 * @Description: 时间超时退出的session设置
 * @Date: Created in 22:12 2020/11/30
 * @ModifiedBy:
 */
@WebFilter("/*")
public class NeeFilter implements Filter {
    public void destroy() {
    }

    /**
     * @Description: 獲取每次操作刷新時間,並將時間放入會話域Session中其key為pcmember
     * @Param: [req, resp, chain]
     * @return: void
     * @Author: Mr.yuan
     * @Date: 2020/12/1
     */
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) req;

        HttpSession session = request.getSession();
        session.setAttribute("pcmember", new Date().getTime());

        chain.doFilter(req, resp);
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
